package com.jctrip.hotel.management.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.jctrip.hotel.management.model.param.GetFinanceInfoParam;
import com.jctrip.hotel.management.model.param.UpdateHotelAccountRechargeParam;
import com.jctrip.hotel.management.model.result.*;
import com.jctrip.hotel.management.service.FinanceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.text.ParseException;
import java.util.List;

@Slf4j
@Api(tags = "finance")
@RestController
@RequestMapping("/management/finance")
public class FinanceController {
    @Autowired
    private FinanceService financeService;

    @PostMapping("/listInfo")
    @ApiOperation(value = "listInfo", notes = "获取财务报表")
    @ApiOperationSupport(order = 1)
    public Result<GetFinanaceInfoResult> listOrder(@RequestBody GetFinanceInfoParam param){
        return Result.ok(financeService.getFinanaceInfo(param));
    }

    @GetMapping("/purchase")
    @ApiOperation(value = "purchase", notes = "采购报表")
    @ApiOperationSupport(order = 2)
    public Result<GetPurchaseResult> purchase(@RequestParam(value = "date", required = false)String date,
                                              @RequestParam(value = "pageNo", defaultValue = "1")Long pageNo,
                                              @RequestParam(value = "pageSize", defaultValue = "10")Long pageSize) throws ParseException {
        return Result.ok(financeService.purchase(date, pageNo, pageSize));
    }

    @GetMapping("/hotelAccount")
    @ApiOperation(value = "hotelAccount", notes = "授信管理list")
    @ApiOperationSupport(order = 3)
    public Result<GetAccountResult> hotelAccount(@RequestParam(value = "pageNo", required = false, defaultValue = "1")Long pageNo,
                                                 @RequestParam(value = "pageSize", required = false, defaultValue = "10")Long pageSize,
                                                 @RequestParam(value = "channelType", required = false)String routeCode,
                                                 @RequestParam(value = "sellerName", required = false)String routeName){
        return Result.ok(financeService.hotelAccount(pageNo, pageSize, routeCode, routeName));
    }

    @PostMapping("/hotelAccountRecharge")
    @ApiOperation(value = "hotelAccountRecharge", notes = "用户充值")
    @ApiOperationSupport(order = 4)
    public Result<String> hotelAccountRecharge(@RequestBody UpdateHotelAccountRechargeParam param, HttpServletRequest request){
        return Result.ok(financeService.hotelAccountRecharge(param, request));
    }

    @GetMapping("/hotelAccountLog")
    @ApiOperation(value = "hotelAccountLog", notes = "用户账日志")
    @ApiOperationSupport(order = 5)
    public Result<List<GetHotelAccountLogResult>> hotelAccountLog(@RequestParam(value = "routeId",required = true)String routeId){
        return Result.ok(financeService.hotelAccountLog(routeId));
    }

//    @GetMapping("/market")
//    @ApiOperation(value = "market", notes = "采购报表")
//    @ApiOperationSupport(order = 2)
//    public Result<MarketResult> market(@RequestParam(value = "date", required = false)String date,
//                                       @RequestParam(value = "pageNo", defaultValue = "1")Long pageNo,
//                                       @RequestParam(value = "pageSize", defaultValue = "10")Long pageSize) throws ParseException {
//        return Result.ok(financeService.market(date, pageNo, pageSize));
//    }

    @GetMapping("/getUserAccount")
    @ApiOperation(value = "getUserAccount", notes = "获取账户余额")
    @ApiOperationSupport(order = 6)
    public Result<String> getUserAccount(@RequestParam String routeId) {
        return Result.ok(financeService.getUserAccount(routeId));
    }
}
